package com.coy.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * web应用配置
 *
 * @author chenck
 * @date 2019/11/19 22:16
 */
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

    /**
     * session 拦截器
     */
    @Bean
    public SessionHandlerInterceptor sessionHandlerInterceptor() {
        return new SessionHandlerInterceptor();
    }

    /**
     * 可定义多个拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(this.sessionHandlerInterceptor());
        // 定义不拦截的path
        interceptorRegistration.excludePathPatterns("/");
        interceptorRegistration.excludePathPatterns("/register");
        interceptorRegistration.excludePathPatterns("/login");
        // 定义拦截的path
        interceptorRegistration.addPathPatterns("/**");
        super.addInterceptors(registry);
    }


}
